package org.framework.common.api.entity;

import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.framework.common.ext.util.JsonUtil;
import org.framework.common.ext.util.StringUtil;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 系统消息
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date 2016年5月16日 下午7:15:07
 * @version 1.0.2016
 */
@Entity @Table(name = "TB_CORE_MESSAGE")
public class CommonMessage extends CommonEntityUUID {

	/** serialVersionUID(long):. */
	private static final long serialVersionUID = 4686905844660793004L;

	// 消息图标
	@Column(name = "icon", length = 50, nullable = true)
	private String icon;
	
	// 消息提示
	@Column(name = "info", length = 500, nullable = true)
	private String info;
	
	// 消息标题
	@Column(name = "title", length = 500, nullable = true)
	private String title;

	// 消息内容
	@Lob @Basic(fetch=FetchType.LAZY)
	@Column(name = "message", nullable = true)
	private String message;
	
	// 用户ID
	@Column(name = "user_id", length = 50, nullable = true)
	private String userid;
	
	// 用户
	@Column(name = "user_name", length = 50, nullable = true)
	private String username;

	// 发送时间
	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "create_date", nullable = true)
	private Date createDate;

	@JsonIgnore
	public String getTextMessage() {
		return StringUtil.isNotEmpty(title) ? JsonUtil.serialize(this) : null;
	}
	
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
}
